#include "alloy.h"
#include "tools.h"


Alloy_var::Alloy_var( char * file, double Pz_fraction, double Psp_fraction) {

  FILE * fp;
  fopen_s(&fp,file,"r");
  if ( fp==NULL ) {
    printf("READ_MATERIAL: Cannot open file %s\n",file);
    exit(1);
  };

  skip_line(fp);
  fscanf_s(fp,"%lf",&eps0);
  eps1		= next(fp);
  eps2		= next(fp);
  cb_offset0    = next(fp);
  cb_offset1    = next(fp);
  Eg0		= next(fp);
  Eg1		= next(fp);
  Eg2		= next(fp);
  bowing0	= next(fp);
  bowing1	= next(fp);
  mob_n0	= next(fp);
  mob_n1	= next(fp);
  mob_n2	= next(fp);
  mob_p0	= next(fp);
  mob_p1	= next(fp);
  mob_p2	= next(fp);
  Tn0		= next(fp);
  Tn1		= next(fp);
  Tn2		= next(fp);
  Tp0		= next(fp);
  Tp1		= next(fp);
  Tp2		= next(fp);
  me0		= next(fp); 
  me1		= next(fp);
  me2		= next(fp);
  mh0		= next(fp); 
  mh1		= next(fp);
  mh2		= next(fp);
  Edon_ion      = next(fp);
  Eacc_ion      = next(fp);
  skip_line(fp);
  a0		= next(fp);
  a1		= next(fp);
  a2		= next(fp);
  c0            = next(fp);
  c1            = next(fp);
  c2            = next(fp);
  e33_0	        = Pz_fraction*next(fp);
  e33_1 	= Pz_fraction*next(fp);
  e33_2 	= Pz_fraction*next(fp);
  e31_0	        = Pz_fraction*next(fp);
  e31_1 	= Pz_fraction*next(fp);
  e31_2 	= Pz_fraction*next(fp);
  poisson_ratio_0 = next(fp);
  poisson_ratio_1 = next(fp);
  poisson_ratio_2 = next(fp);
  Psp0		= Psp_fraction*next(fp);
  Psp1		= Psp_fraction*next(fp);
  Psp2		= Psp_fraction*next(fp);
  skip_line(fp);
  Etraps_e      = next(fp);
  Ntraps        = next(fp);
  Tntraps       = next(fp);
  Etraps_h      = next(fp);
  Ptraps        = next(fp);
  Tptraps       = next(fp);

  Nc0		= 2.0e-6*pow(2.0*PI*me0*VT*(MASS/PLANK)*(Q/PLANK),1.5);  /* Sze */
  Nc1  		= 2.0e-6*pow(2.0*PI*me1*VT*(MASS/PLANK)*(Q/PLANK),1.5);
  Nc2  		= 2.0e-6*pow(2.0*PI*me2*VT*(MASS/PLANK)*(Q/PLANK),1.5);
  Nv0		= 2.0e-6*pow(2.0*PI*mh0*VT*(MASS/PLANK)*(Q/PLANK),1.5);
  Nv1		= 2.0e-6*pow(2.0*PI*mh1*VT*(MASS/PLANK)*(Q/PLANK),1.5);
  Nv2		= 2.0e-6*pow(2.0*PI*mh2*VT*(MASS/PLANK)*(Q/PLANK),1.5);

  fclose(fp);

}

/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */

void Alloy_var::show() {

  printf("eps0=%le eps1=%le eps2=%le\n",eps0,eps1,eps2);
  printf("Nc0=%le Nc1=%le Nc2=%le\n",Nc0,Nc1,Nc2);
  printf("Nv0=%le Nv1=%le Nv2=%le\n",Nv0,Nv1,Nv2);
  printf("Eg0=%le Eg1=%le Eg2=%le bowing0=%le bowing1=%le\n",Eg0,Eg1,Eg2,bowing0,bowing1);
  printf("cb_offset0=%le cb_offset1=%le\n",cb_offset0,cb_offset1);
  printf("mob_n0=%le mob_n1=%le mob_n2=%le\n",mob_n0,mob_n1,mob_n2);
  printf("mob_p0=%le mob_p1=%le mob_p2=%le\n",mob_p0,mob_p1,mob_p2);
  printf("Tn0=%le Tn1=%le Tn2=%le\n",Tn0,Tn1,Tn2);
  printf("Tp0=%le Tp1=%le Tp2=%le\n",Tp0,Tp1,Tp2);
  printf("me0=%le me1=%le me2=%le\n",me0,me1,me2);
  printf("mh0=%le mh1=%le mh2=%le\n",mh0,mh1,mh2);
  printf("a0=%le a1=%le a2=%le\n",a0,a1,a2);
  printf("c0=%le c1=%le c2=%le\n",c0,c1,c2);
  printf("Psp0=%le Psp1=%le Psp2=%le\n",Psp0,Psp1,Psp2);
  printf("Edon_ion=%le Eacc_ion=%le Ntraps=%le Etraps_e=%le Ptraps=%le Etraps_h=%le\n",Edon_ion,Eacc_ion,Ntraps,Etraps_e,Ptraps,Etraps_h);

}

/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */

